<template>
  <div class="app-container rebate-rules">
    <el-row justify="space-between" align="middle">
      <el-form class="alone-business" :model="queryData" ref="queryDataRef" :inline="true" label-width="68px">
        <el-form-item label="工厂名称" prop="factoryName">
          <el-input v-model="queryData.factoryName" placeholder="请输入姓名或者手机号" clearable style="width: 200px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="searchData">查询</el-button>
          <el-button icon="Refresh" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-radio-group v-model="queryData.isRisk">
        <el-radio :value="true" @click.prevent="channelRadioClick(true)"><el-text type="danger">存在风险</el-text></el-radio>
      </el-radio-group>
    </el-row>
    <!-- <el-tabs v-model="queryData.activeName" class="demo-tabs" @tab-change="tabClick">
      <el-tab-pane :name="1">
        <template #label>
          <el-text type="danger">存在风险</el-text>
        </template>
      </el-tab-pane>
      <el-tab-pane label="全部" :name="0"></el-tab-pane>
    </el-tabs> -->
    <el-table v-loading="tableLoading" :data="tableData" highlight-current-row style="width: 100%; margin-top: 20px">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column property="factoryName" label="工厂名称" width="250" />
      <el-table-column property="factoryDepositAmount" label="应缴纳保证金金额" />
      <el-table-column property="factoryRemainingDeposit" label="剩余保证金金额" />
      <el-table-column property="factoryDepositRechargeRatio" label="每单充值比例" />
      <el-table-column property="purchasePayableAmount" label="集采剩余应返金额" width="180" />
    </el-table>
    <pagination :total="listTotal" v-model:page="queryData.current" v-model:limit="queryData.size" @pagination="getTable" />
  </div>
</template>
<script setup>
import { onMounted } from "vue";
import { pageList } from "@/api/system/rebateRules/earnestMoney";

// 搜索条件
const queryData = ref({
  factoryName: "",
  isRisk: true,
  current: 1,
  size: 10
});

// 表格总数
const listTotal = ref(0);

const channelRadioClick = e => {
  e === queryData.value.isRisk ? (queryData.value.isRisk = false) : (queryData.value.isRisk = e);
  getTable();
};

// 查询
const searchData = () => {
  getTable();
};

// 搜索重置
const reset = () => {
  queryData.value = {
    factoryName: "",
    isRisk: true,
    current: 1,
    size: 10
  };
  getTable();
};

const tabClick = tab => {
  console.log(tab);
};

// 表格数据
const tableData = ref([]);
const tableLoading = ref(false);

// 获取表格数据
const getTable = () => {
  tableLoading.value = true;
  pageList(queryData.value).then(res => {
    tableData.value = res.data.list;
    listTotal.value = res.data.total;
    tableLoading.value = false;
  });
};

onMounted(() => {
  getTable();
});
</script>
<style lang="scss" scoped></style>
